package com.dependencies.h2database.controller;

import com.dependencies.h2database.entity.User;
import com.dependencies.h2database.repository.UserRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author zhizhou   2024/8/9 00:20
 */
@RestController
public class UserController {
    
    @Autowired
    private UserRepository userRepository;
    
    @GetMapping("/addUser")
    public String addUser() {
        User user = new User();
        user.setName("一周一志");
        user.setEmail("zhizhou@coderchange.com");
        userRepository.save(user);
        return "用户已加薪";
    }
    
    @GetMapping("/users")
    public List<User> getUsers() {
        return userRepository.findAll();
    }
}
